package com.xqboss.apps.service.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.apps.domain.order.OrderItem;
import com.xqboss.apps.mapper.order.OrderItemMapper;
import com.xqboss.common.exception.ServiceException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Trent
 * @date 2023/8/24
 */
@Service
public class OrderItemService extends ServiceImpl<OrderItemMapper, OrderItem> {

    public OrderItem requireOrderItemByOrderMainId(Long orderMainId){
        OrderItem orderItem = getOne(new LambdaQueryWrapper<OrderItem>()
                .eq(OrderItem::getOrderMainId, orderMainId));
        if(orderItem == null){
            throw new ServiceException("订单不存在！");
        }
        return orderItem;
    }

    public List<OrderItem> getItemsByOrderMain(Long orderMainId) {
        List<OrderItem> items = list(new LambdaQueryWrapper<OrderItem>()
                .eq(OrderItem::getOrderMainId, orderMainId));
        return items;
    }
}
